package testdemo.service.impl;

import edu.nf.beans.annotations.Component;
import edu.nf.beans.annotations.Inject;
import testdemo.dao.NoticeDao;
import testdemo.dao.impl.NoticeDaoImpl;
import testdemo.exception.LoginException;
import testdemo.model.Notice;
import testdemo.service.NoticeService;

import java.util.Date;
import java.util.List;
import java.util.Map;
@Component("NoticeService")
public class NoticeServiceImpl implements NoticeService {
    @Inject(name = "noticeDao")
    private NoticeDao noticeDao;

    @Override
    public List<Map<String, Object>> getAllnotice() {
        List<Map<String, Object>> allnotice = noticeDao.getAllnotice();
        if (allnotice.size()==0){
            throw new  LoginException("获取数据失败");
        }
        return allnotice;
    }

    @Override
    public void deleteNotice(int id) {
      try{
          noticeDao.deleteNotice(id);
          }catch(Exception e){
           throw new LoginException("删除失败");
         }
      }

    @Override
    public void updateNotice(int id) {
        try{
            noticeDao.updateNotice(id);
        }catch (Exception e){
            throw  new LoginException("更新失败");
        }
    }

    @Override
    public void addNotice(Integer id, String title, String content, Date time) {
        try{
            noticeDao.addNotice(id, title, content, time);
        }catch (Exception e){
            throw  new LoginException("添加失败");
        }
    }
}
